<#
.SYNOPSIS
	Return the current dfm settings on the storage appliance.
.DESCRIPTION
	Return the current dfm settings on the storage appliance.
.PARAMETER Server
   	NaServer to query
.EXAMPLE
  	Get-NaDFMServer
.OUTPUTS
	NetApp.SDK.NaDFMServerInfo
.Link
	Set-NaDFMServer
#> 
function Get-NaDFMServer {
	[CmdletBinding(SupportsShouldProcess=$FALSE,SupportsTransactions=$False,ConfirmImpact="None",DefaultParameterSetName="")]
	param(
		[Parameter(Position=0,HelpMessage="NaServer to query")]
		[NetApp.SDK.NaServer]
		$Server = (Get-NaServer)
	)
	Process {
		$request = New-Object Netapp.Manage.NaElement -ArgumentList @("dfm-get-server-info")
		try {
			$result = ([xml]$server.InvokeElem($request)).results
		}
		catch [NetApp.Manage.NaApiFailedException]{
			Write-Warning $_.Exception.GetBaseException().message
			$result = $null
			continue;
		}
		if ($?) {
			return New-Object NetApp.SDK.NaDFMServerInfo -ArgumentList @(
				$result."dfm-server",
				(ConvertFrom-NaBool $result."is-dfm-cross-linked"),
				$result."port",
				$result."protocol"
			)
		}
	}
}
<#
.SYNOPSIS
	Set the current dfm settings on the storage appliance.
.DESCRIPTION
	Set the current dfm settings on the storage appliance.
.PARAMETER DFMServer
	DFM server identifier. If not supplied then clear the current value. 
.PARAMETER CrossLinked
	When this setting is true, FilerView provides cross-links to the specified DFM server. 
.PARAMETER Port
	Port used for DFM requests. If not supplied then clear the current value.
.PARAMETER Protocol
	Protocol in use by DFM. Possible values are "http" and "https". If not supplied then clear the current value. 
.PARAMETER Server
   	NaServer to query
.EXAMPLE
  	Set-NaDFMServer -DFMServer server15 -Port 42 -Protocol https -CrossLinked $true
.OUTPUTS
	NetApp.SDK.NaDFMServerInfo
.Link
	Get-NaDFMServer
#>
function Set-NaDFMServer {
	[CmdletBinding(SupportsShouldProcess=$True,SupportsTransactions=$False,ConfirmImpact="Low")]
	param(
		[Parameter(Position=0,ValueFromPipelineByPropertyName=$TRUE)]
		[AllowNull()]
		[string]
		$DFMServer,
	
		[Parameter(Position=1,ValueFromPipelineByPropertyName=$TRUE)]
		[bool]
		$CrossLinked,
	
		[Parameter(Position=2,ValueFromPipelineByPropertyName=$TRUE)]
		[int16]
		$Port,
	
		[Parameter(Position=3,ValueFromPipelineByPropertyName=$TRUE)]
		[ValidateSet("http","https")]
		[string]
		$Protocol,
	
		[Parameter(HelpMessage="NaServer to query")]
		[NetApp.SDK.NaServer]
		$server = (Get-NaServer)
	)
	Process {
		$request = New-Object Netapp.Manage.NaElement -ArgumentList @("dfm-set-server-info")
		$request.AddNewChild("dfm-server",$DFMServer)
		$request.AddNewChild("is-dfm-cross-linked",$CrossLinked)
		$request.AddNewChild("port", $Port)
		$request.AddNewChild("protocol",$Protocol)
		if (!$DFMServer -and !$Port -and !$Protocol) {
			if ($pscmdlet.ShouldContinue($Server.Server, "Are you sure you want to clear DFM")) {
				try {
					$server.Invoke("dfm-set-server-info")|out-null
				}
				catch [NetApp.Manage.NaApiFailedException]{
					Write-Warning $_.Exception.GetBaseException().message
					continue;
				}
			}
		} 
		else {
			$msg = "Setting DFM to {0}://{1}:{2}, and {3} cross linked" -f $Protocol,$DFMServer,$Port,$(if($CrossLinked){"enabling"}else{"disabling"})
			if ($pscmdlet.ShouldProcess($Server.Server,$msg)){
				try {
					$server.InvokeElem($request)|out-null
				}
				catch [NetApp.Manage.NaApiFailedException]{
					Write-Warning $_.Exception.GetBaseException().message
					continue;
				}
				if ($?){
					Get-NaDFMServer -Server $Server
				}
			}
		}
	}
}
<#
.SYNOPSIS
	Removes dfm settings on the storage appliance.
.DESCRIPTION
	Removes dfm settings on the storage appliance.
.EXAMPLE
  	Remove-NaDFMServer
.Link
	Get-NaDFMServer
#>
function Remove-NaDFMServer {
	[CmdletBinding(SupportsShouldProcess=$True,SupportsTransactions=$False,ConfirmImpact="Low")]
	param(
		[Parameter(HelpMessage="NaServer to query")]
		[NetApp.SDK.NaServer]
		$server = (Get-NaServer)
	)
	Process {
		if ($pscmdlet.ShouldProcess($Server.Server, "Are you sure you want to clear DFM")) {
			try {
				$server.Invoke("dfm-set-server-info")|out-null
			}
			catch [NetApp.Manage.NaApiFailedException]{
				Write-Warning $_.Exception.GetBaseException().message
				continue;
			}
		} 
	}
}